package com.gw.quotes.net.service;

import org.ksoap2.serialization.SoapObject;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.gw.quotes.entity.business.OrderInfoEntity;
import com.gw.quotes.net.NewException;
import com.gw.quotes.net.Request;
import com.gw.quotes.net.Response;

public class OrderInfoQueryServiceImpl extends WebBaseServiceImpl {
	
	@Override
	public Response setResponse() {
		return new OrderInfoEntity();
	}

	@Override
	public void checkParam(Request request) throws NewException {
		if (request == null) {
			throw new NewException(Response.RESULT_ERROR, "传入request不能为空");
		}
		if (checkNull(request.getLoginname())) {
			throw new NewException(Response.RESULT_ERROR, "用户登录名不能为空");
		}
		if (checkNull(request.getTicket())) {
			throw new NewException(Response.RESULT_ERROR, "接口凭据不能为空");
		}
		if (checkNull(request.getOrderguid())) {
			throw new NewException(Response.RESULT_ERROR, "Orderguid不能为空");
		}
	}

	@Override
	public void setParamByRequest(Request request, SoapObject rpc)
			throws NewException {
		rpc.addProperty("arg0", request.getOrderguid());
		rpc.addProperty("arg1", request.getLoginname());
		rpc.addProperty("arg2", request.getTicket());
		// rpc.addProperty("arg2", request.getJsonconditions());
	}

	@Override
	public void resolveResponse(Object object, Response response)
			throws NewException {
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
				.create();
		java.lang.reflect.Type type = new TypeToken<OrderInfoEntity>() {
		}.getType();
//		String string="{'result':1,'order':{'total':'97713','buyerorgname':'杭州市公安局','orderguid':'2c909bf147d8a73a0147d8a853800002','status':2,'qty':'21','ordertype':1,'orderGoodsList':[{'goodsname':'三星 2014年笔记本标项七 NP2470EV-EGACN','finalprice':'4653','orderguid':'2c909bf147d8a73a0147d8a853800002','orderOptionalList':[{'finalprice':'1200','orderoptionalguid':'169494aa46428aaf01464aa7384b1f17','qty':'1','optioncontent':'4G换16G'}],'orderAccessorieList':[      {       'goodsname':'戴尔 CPU 英特尔？ 至强？ E5-2630',       'finalprice':'7000',       'goodsguid':'169494aa45dc1b9f0145de99a758055d',       'orderaccessoryguid':'169494aa46428aaf01464aa7383c1f0d',       'qty':1,       'ordergoodsguid':'169494aa46428aaf01464aa7382c1f0c',       'priceguid':'169494aa45f8fedf0145fd765522591e',       'imgurl':'http://cg.hzft.gov.cn/gpos/upload/picture/2014/4/24/1398348386213_standardpath_factpath.jpg'      }     ],'goodsguid':'169494aa45d141410145d4ee999b0a94','finaltotal':'97713','ordergoodsguid':'2c909bf147d8a73a0147d8a853e60003','priceguid':'169494aa45d141410145d4f2ae780aeb','imgurl':'http://cg.hzft.gov.cn/gpos/upload/picture/2014/5/7/1399436771290_standardpath_factpath.jpg'}],'goodsclassname':'笔记本电脑','code':'HZZFCG-DD-2014-34420','hasContract':true}}";
		OrderInfoEntity result = gson.fromJson(object.toString(), type);
		setResponse(result);
		System.out.println("object" + object.toString());
	}

	@Override
	public String getMethodName() throws NewException {
		return "getOrdertinfo";
	}
}
